# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=gtk4
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.94.0
pkgrel=1
pkgdesc="GObject-based multi-platform GUI toolkit (v4) (mingw-w64)"
arch=('any')
url="https://www.gtk.org"
license=("LGPL")
install=gtk4-${CARCH}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-meson")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-atk"
         "${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-graphene"
         "${MINGW_PACKAGE_PREFIX}-json-glib"
         "${MINGW_PACKAGE_PREFIX}-libepoxy"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-bad"
         "${MINGW_PACKAGE_PREFIX}-gtk3" # for the conflicting files
         "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
options=('strip' '!debug')
source=("https://download.gnome.org/sources/gtk+/${pkgver%.*}/gtk+-${pkgver}.tar.xz")
sha256sums=('a947caa5296610b0f1d7a03b58df34765c227c577c78e683e75eea3251a67035')

prepare() {
  cd "${srcdir}/gtk+-${pkgver}"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  meson \
    -Dbuild-examples=false \
    -Dbuild-tests=false \
    -Dman-pages=true \
    -Dvulkan=no \
    ../gtk+-${pkgver}

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  for pcfile in "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pcfile}"
  done

  # In conflict with gtk3
  rm "${pkgdir}${MINGW_PREFIX}"/share/gettext/its/gtkbuilder{.its,.loc}
  rm "${pkgdir}${MINGW_PREFIX}"/share/glib-2.0/schemas/org.gtk.Demo.gschema.xml
  rm "${pkgdir}${MINGW_PREFIX}"/share/glib-2.0/schemas/org.gtk.Settings.{ColorChooser,Debug,EmojiChooser,FileChooser}.gschema.xml

  install -Dm644 "${srcdir}/gtk+-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
